library flutter_reader_paging;

import 'package:flutter/material.dart';

/// A Calculator.
class ReaderPagingCalulator {
  static int maxChineseCharCount(
      double width, double maxHeight, double textSize) {
    int count = 1;
    while (true) {
      final painter = TextPainter(
        text: TextSpan(
          text: "一" * count,
          style: TextStyle(
            fontSize: textSize,
          ),
        ),
        textDirection: TextDirection.ltr,
      );
      painter.layout(minWidth: width, maxWidth: width);
      if (painter.size.height > maxHeight) {
        return count - 1;
      }
      count++;
    }
  }

  static int lineMaxWidth(double width, double maxHeight, double textSize) {
    int count = 1;
    double firstHeight = 0;
    do {
      final painter = TextPainter(
        text: TextSpan(
          text: "一" * count,
          style: TextStyle(
            fontSize: 15,
          ),
        ),
        textDirection: TextDirection.ltr,
      );
      painter.layout(minWidth: width, maxWidth: width);

      if (firstHeight == 0) {
        firstHeight = painter.size.height;
      }

      if (painter.size.height > firstHeight) {
        return count - 1;
      }
      count++;
    } while (true);
  }
}
